import tkinter

from Attriabte.DTO import BasicWidgetDto, ColorHoverWidgetDto, MoveAnimalDto, LayoutDto
from Entiy.WordGroup import WordGroup
from View.MainWindow import MainWindow
from View.WindowComponent.BasicHoverLabel import BasicHoverLabel
from View.WindowComponent.BodyFrame.ModeSelectFrame import ModeSelectFrame
from View.WindowComponent.BodyFrame.Main import MainFrame
from View.WindowComponent.BodyFrame.ManagerFrame import ManagerFrame
from View.WindowComponent.BodyFrame.Setting import Setting
from View.WindowComponent.ColorHoverLabel import ColorHoverLabel
from View.WindowComponent.Layout.LayoutSide import LayoutSide
from View.WindowThread import GetSound
from View.WindowThread.BasicAnimal import MoveAnimal
from View.WindowThread.ThreadManager import ThreadManager
import customtkinter

customtkinter.set_default_color_theme("green")

def frame_sroller():
    import tkinter as tk
    from tkscrollframe import ScrollFrame

    root = tk.Tk()
    sf = ScrollFrame(root)

    frame = sf.viewPort  # is important

    # add some widget to frame sf
    for i in range(20):
        tk.Label(frame, text=f"text in line {i}").pack()
    print(sf)
    sf.pack()
    root.mainloop()

def MainFrame_Test():
    app = MainWindow()

    Config = ColorHoverWidgetDto(text='主页', hover_fg='green', hover_bg='black')
    Config2 = ColorHoverWidgetDto(text='单词管理', hover_fg='green', hover_bg='black')
    Config3 = ColorHoverWidgetDto(text='开始学习', hover_fg='green', hover_bg='black')
    Config4 = ColorHoverWidgetDto(text='设置', hover_fg='green', hover_bg='black')
    label = []
    frame = []
    layoutSide = LayoutSide(app, label, frame, LayoutDto(color_style='Zebra', hover_children=True))
    frame.append(MainFrame(layoutSide,False).get())
    frame.append(ManagerFrame(layoutSide,True).get())
    frame.append(ModeSelectFrame(layoutSide,False).get())
    frame.append(Setting(layoutSide,False).get())
    print(frame)
    label.append(ColorHoverLabel(layoutSide.frame_side, Config))
    label.append(ColorHoverLabel(layoutSide.frame_side, Config2))
    label.append(ColorHoverLabel(layoutSide.frame_side, Config3))
    label.append(ColorHoverLabel(layoutSide.frame_side, Config4))
    layoutSide.put()
    app.show()


def LayoutSide_Test():
    app = MainWindow()
    list_label = []
    frame = []
    # 创建layout label的dto

    Config = ColorHoverWidgetDto(text='标签', hover_fg='green', hover_bg='black')
    Config2 = ColorHoverWidgetDto(text='标签2', hover_fg='green', hover_bg='red')

    # 创建layout
    layoutDto = LayoutDto(color_style="Zebra", hover_children=True)
    print(layoutDto.hover_children)

    layout = LayoutSide(app.MainWidow, list_label, frame, layoutDto)

    # frame与frame 的装饰
    frame1 = layout.Data. getFrameInstance(BasicWidgetDto(bg='green'))
    frame2 = layout.Data. getFrameInstance(BasicWidgetDto(bg='red'))
    frame3 = layout.Data. getFrameInstance(BasicWidgetDto(bg='blue'))
    tkinter.Label(frame1, text='1', bg='red').place(x=0, y=0)
    tkinter.Label(frame2, text='2', bg='red').place(x=0, y=0)
    tkinter.Label(frame3, text='3', bg='red').place(x=0, y=0)
    frame.append(frame1)
    frame.append(frame2)
    frame.append(frame3)

    # 创建llabel|
    colorHoverLabel = ColorHoverLabel(layout.frame_side, Config)
    colorHoverLabel2 = ColorHoverLabel(layout.frame_side, Config2)

    # 将label加入list_label
    list_label.append(colorHoverLabel)
    list_label.append(colorHoverLabel2)

    # 布置布局
    layout.put()

    app.show()


def ColorHoverLabel_Test():
    app = MainWindow()
    window = app.MainWidow
    config = ColorHoverWidgetDto("测试文本")
    basicHoverLabel = ColorHoverLabel(window, config)
    basicHoverLabel.get().pack()
    app.show()


def BasicHoverLabel_Test():
    app = MainWindow()
    window = app.MainWidow
    config = BasicWidgetDto("测试文本")
    basicHoverLabel = BasicHoverLabel(window, config)
    basicHoverLabel.get().pack()
    app.show()


def MoveAnimal_Text():
    app = MainWindow()
    win = app.MainWidow

    mat = MoveAnimalDto(
        from_site=(0, 0),
        to_site=(100, 200),
        frame=100
    )

    con = BasicWidgetDto("测试文本")
    label = ColorHoverLabel(win, con).get()
    moveAnimal = MoveAnimal(win, label, mat)
    ThreadManager(moveAnimal)

    app.show()

def models_word():
    wg = WordGroup()
    wg.new_group("Hello")
    print(wg.group_register)
    print(wg.load_group("test2", True))
    print(wg.get_all_word())

def table_test():
    from pandastable import Table
    app = tkinter.Tk()
    pt = Table(parent=app)
    pt.importCSV("./resource/word.xlsx")
    pt.show()
    app.mainloop()

if __name__ == '__main__':
    MainFrame_Test()
